What is ansi?
The 'ansi' npm package provides a set of utilities for working with ANSI escape codes, which are used to control text formatting, color, and other output options on text terminals. This package allows you to manipulate text output in the terminal, making it more readable and visually appealing.
What are ansi's main functionalities?
Text Formatting
This feature allows you to format text in the terminal. The example code demonstrates how to make text bold using the 'ansi' package.
const ansi = require('ansi');
const cursor = ansi(process.stdout);
cursor.bold().write('Bold text').reset();
Text Coloring
This feature allows you to change the color of the text in the terminal. The example code shows how to make text red using the 'ansi' package.
const ansi = require('ansi');
const cursor = ansi(process.stdout);
cursor.red().write('Red text').reset();
Cursor Positioning
This feature allows you to move the cursor to a specific position in the terminal. The example code demonstrates how to move the cursor to position (10, 5) and write text there using the 'ansi' package.
const ansi = require('ansi');
const cursor = ansi(process.stdout);
cursor.goto(10, 5).write('Text at position (10, 5)').reset();
Other packages similar to ansi
chalk
Chalk is a popular package for styling terminal strings. It provides a simpler and more intuitive API for applying colors and styles to text. Unlike 'ansi', which focuses on low-level ANSI escape codes, 'chalk' abstracts these details away, making it easier to use.
colors
Colors is another package for adding color and style to terminal output. It offers a wide range of color and style options and is known for its ease of use. Compared to 'ansi', 'colors' provides a more user-friendly API for common text styling tasks.
cli-color
CLI-Color is a package that provides a comprehensive set of tools for styling terminal output. It supports nested styles and offers a rich set of features for text formatting and coloring. CLI-Color is more feature-rich compared to 'ansi', making it suitable for complex styling needs.
ansi.js
Advanced ANSI formatting tool for Node.js
ansi.js
is a module for Node.js that provides an easy-to-use API for
writing ANSI escape codes to Stream
instances. ANSI escape codes are used to do
fancy things in a terminal window, like render text in colors, delete characters,
lines, the entire window, or hide and show the cursor, and lots more!
Features:
- 256 color support for the terminal!
- Make a beep sound from your terminal!
- Works with any writable
Stream
instance. - Allows you to move the cursor anywhere on the terminal window.
- Allows you to delete existing contents from the terminal window.
- Allows you to hide and show the cursor.
- Converts CSS color codes and RGB values into ANSI escape codes.
- Low-level; you are in control of when escape codes are used, it's not abstracted.
Installation
Install with npm
:
$ npm install ansi
Example
var ansi = require('ansi')
, cursor = ansi(process.stdout)
cursor
.red()
.bg.grey()
.write('Hello World!')
.bg.reset()
.write('\n')
cursor.hex('#660000').bold().underline()
console.log('This is blood red, bold text')
cursor.fg.reset()
console.log('This will still be bold')
cursor.goto(10, 5).write('Five down, ten over')
cursor.horizontalAbsolute(0).eraseLine().write('Starting again')
cursor.horizontalAbsolute(5).write('column five')
cursor.reset()
License
(The MIT License)
Copyright (c) 2012 Nathan Rajlich <nathan@tootallnate.net>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.